<?php

class Top10 extends Portlet {

    const TYPE_RATNG = 1;
    const TYPE_HELPED = 2;
    const TYPE_HELPED_US = 3;

    public $type;

    protected function renderContent() {
        $criteria = new CDbCriteria();
        if($this->type == self::TYPE_RATNG) {
            $criteria->order = "rating DESC";
            $criteria->select = "id,username, email, lastvisit,rating";
        } elseif($this->type == self::TYPE_HELPED) {
            $criteria->order = "helped DESC";
            $criteria->select = "id,username, email, lastvisit, helped as rating";
        } elseif($this->type == self::TYPE_HELPED_US) {
            $criteria->order = "helped_us DESC";
            $criteria->select = "id,username, email, lastvisit, helped_us as rating";
        }
        $criteria->limit = 10;
        $users = User::model()->cache(60)->findAll($criteria);
        $this->render("top10", compact('users'));
    }
}
